import request from "@/service/request";
import requestAly from "@/service/requestAly";
import {PromisePageResponse, PromiseResponse} from "@/service/api/type.ts";
import {CourseDailyKnowledgeVo, OssUploadAuth} from "@/service/api/course/knowledge/types.ts";

/**
 * 获取上传凭证
 * @param query
 */
const getOssAuth = (query: any): PromiseResponse<OssUploadAuth> => {
  return request({
    url: "/system/oss/uploadAuth",
    method: "get",
    params: query,
  });
};

/**
 * 文件上传到OSS
 * @param File
 */
const postToOSS = (File: any) => {
  return requestAly({
    url: ``,
    method: "post",
    data: File,
  });
};

/**
 * 添加知识
 * @param query
 */
const createKnowledge = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/knowledge",
    method: "post",
    data: query,
  });
};

/**
 * 获取今日知识
 */
const getTodayKnowledge = (): PromiseResponse<CourseDailyKnowledgeVo> => {
  return request({
    url: "/course/knowledge/today",
    method: "get",
  });
};

/**
 * 获取知识详情
 * @param id
 */
const getKnowledgeDetail = (id: string): PromiseResponse<CourseDailyKnowledgeVo> => {
  return request({
    url: `/course/knowledge/${id}`,
    method: "get",
  });
};

/**
 * 获取知识列表
 * @param query
 */
const getKnowledgeList = (query: any): PromisePageResponse<CourseDailyKnowledgeVo> => {
  return request({
    url: "/course/knowledge/list",
    method: "get",
    params: query,
  });
};

/**
 * 编辑知识
 * @param query
 */
const updateKnowledge = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/knowledge/edit",
    method: "put",
    data: query,
  });
};

/**
 * 删除知识
 * @param id
 */
const deleteKnowledge = (id: string | string[]): PromiseResponse<any> => {
  return request({
    url: `/course/knowledge/${id}`,
    method: "delete",
  });
};

export {
  getOssAuth,
  postToOSS,
  getTodayKnowledge,
  getKnowledgeList,
  getKnowledgeDetail,
  updateKnowledge,
  createKnowledge,
  deleteKnowledge
};
